﻿using UnityEngine;
using DG.Tweening;

namespace CGF
{
    public class MoveLoop : MonoBehaviour
    {
        public Vector3 fromPos = new Vector3(0, 0, 0);
        public float goDelay = 0f;
        public float goDuration = 1f;
        public Ease goEaseType = Ease.Linear;
        [Space]
        public Vector3 toPos = new Vector3(0, 100, 0);
        public float backoDelay = 0f;
        public float backDuration = 1f;
        public Ease backEaseType = Ease.Linear;

        void Start()
        {
            if (transform.GetType() == typeof(RectTransform))
            {
                (transform as RectTransform).anchoredPosition = fromPos;
            }
            else
            {
                transform.localPosition = fromPos;
            }
        }

        void Go()
        {
            transform.DOLocalMove(toPos, goDuration).SetEase(goEaseType).SetDelay(goDelay).OnComplete(Back);
        }

        void Back()
        {
            transform.DOLocalMove(fromPos, backDuration).SetEase(backEaseType).SetDelay(backoDelay).OnComplete(Go);
        }

    }
}